(function (doc, win) {
    var docEl = doc.documentElement
    var dpr = win.devicePixelRatio || 1
    // adjust body font size
    function setBodyFontSize () {
      if (doc.body) {
        doc.body.style.fontSize = (12 * dpr) + 'px'
      }
      else {
        doc.addEventListener('DOMContentLoaded', setBodyFontSize)
      }
    }
    setBodyFontSize();
    // set 1rem = viewWidth / 10
    function setRemUnit () {
      var rem = docEl.clientWidth / 10
      docEl.style.fontSize = rem + 'px'
    }
    setRemUnit()
    // reset rem unit on page resize
    win.addEventListener('resize', setRemUnit)
    win.addEventListener('pageshow', function (e) {
      if (e.persisted) {
        setRemUnit()
      }
    })
    // detect 0.5px supports
    if (dpr >= 2) {
      var fakeBody = doc.createElement('body')
      var testElement = doc.createElement('div')
      testElement.style.border = '.5px solid transparent'
      fakeBody.appendChild(testElement)
      docEl.appendChild(fakeBody)
      if (testElement.offsetHeight === 1) {
        docEl.classList.add('hairlines')
      }
      docEl.removeChild(fakeBody)
    }
  })(document, window);